package com.bw.service;

import com.bw.bean.DS;
import com.bw.bean.Dianpu;
import com.bw.bean.Shop;
import com.bw.dao.DianpuDao;
import com.github.pagehelper.util.StringUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class DianpuServicempl implements DianpuService{
    @Resource
    private DianpuDao dianpuDao;
    @Override
    public List<Dianpu> list(Dianpu dianpu) {
        return dianpuDao.list(dianpu);
    }

    @Override
    public List<Shop> getShops() {
        return dianpuDao.getShops();
    }

    @Override
    public void insert(Dianpu dianpu) {
        dianpuDao.insert(dianpu);
    }

    public void inserth(Dianpu dianpu) {
        String sids = dianpu.getSids();
        if(StringUtil.isNotEmpty(sids)){
            ArrayList<Object> list = new ArrayList<>();
            String[] split = sids.split(",");
            for(String s:split){
                DS ds = new DS();
                ds.setDid(dianpu.getDid());
                ds.setSid(s);
                list.add(ds);
            }
            dianpuDao.inserth(list);
        }
    }

    @Override
    public void update(Dianpu dianpu) {
        dianpuDao.update(dianpu);
    }

    @Override
    public Dianpu getid(String id) {
        return dianpuDao.getid(id);
    }
}
